<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>zabbix 配置邮件告警 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>zabbix 配置邮件告警</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Zabbix/">Zabbix</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;设置触发器的目的是为了让监控的服务实现告警，下面来配置一下邮件告警。发邮件是服务器通过子机的 sendmail 服务发出的，有时候如果配置不合适或者服务没有启动，是发不出邮件的。所以，要先测试一下。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># yum install -y sendmail</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;启动服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># /etc/init.d/sendmail start</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># echo "test mail"|mail -s "testtest" 89429541@qq.com</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果提示</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/01.png?raw=true" alt="01"><figcaption class="figure__caption">01</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># yum -y install mailx</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果是虚拟机，很有可能是收不到邮件的，但如果是真机还是可以收到的，只不过有可能在垃圾邮件箱里。下面来配置 zabbix 的邮件告警。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># mkdir -p /home/zabbix/bin</span></div><div class="line">[root@zabbix ~]<span class="comment"># vim /home/zabbix/bin/baojing.sh</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;内容为</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#!/bin/bash</span></div><div class="line"><span class="built_in">echo</span> <span class="string">"<span class="variable">$3</span>"</span>|/bin/mail -s <span class="string">"<span class="variable">$2</span>"</span> <span class="variable">$1</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;保存后，修改文件的权限</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># chmod -x /home/zabbix/bin/baojing.sh</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 /etc/zabbix_server.conf 配置文件中，有参数 AlertScriptePath 和 ExternalScripts ，编辑它</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># vim /etc/zabbix_server.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改如下内容</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/02.png?raw=true" alt="02"><figcaption class="figure__caption">02</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改为（用户自定义的 media type 脚本）</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/03.png?raw=true" alt="03"><figcaption class="figure__caption">03</figcaption></figure></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/04.png?raw=true" alt="04"><figcaption class="figure__caption">04</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改为（用户自定义的检测的脚本 item）</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/05.png?raw=true" alt="05"><figcaption class="figure__caption">05</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下面在浏览器里面继续配置邮件告警</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建 mediea type： “administration”（管理） –&gt; “Media type”（警示媒体类型） </p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/06.png?raw=true" alt="06"><figcaption class="figure__caption">06</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;点击右上角 “Create Media Type”（创建警示媒体类型）</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/07.png?raw=true" alt="07"><figcaption class="figure__caption">07</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;其中 Description（描述） 填 “baojing” 或其他自定义名称</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/08.png?raw=true" alt="08"><figcaption class="figure__caption">08</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Type（类型） 选择 “Script”（脚本）</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/09.png?raw=true" alt="09"><figcaption class="figure__caption">09</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Script 填 “baojing.sh” 然后点 “Save”（存档）</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/10.png?raw=true" alt="10"><figcaption class="figure__caption">10</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建 user：“Administration”（管理）–&gt; “User”（用户）</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/11.png?raw=true" alt="11"><figcaption class="figure__caption">11</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在右上角，选择 “Users”（用户），点击 “Create User”（创建用户） </p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/12.png?raw=true" alt="12"><figcaption class="figure__caption">12</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;alias（别名）：test1，自定义 name（名称） 和 lastname（姓氏） password（密码）：123456； group（组） 选择 guest </p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/13.png?raw=true" alt="13"><figcaption class="figure__caption">13</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;回到上面点一下 media type（示警媒体）</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/14.png?raw=true" alt="14"><figcaption class="figure__caption">14</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;选择 baojing ，send to（收件人） 写要发送邮件的邮箱，点 add（添加） </p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/15.png?raw=true" alt="15"><figcaption class="figure__caption">15</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;最后点 save（存档）</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建action: “configuration”（配置） –&gt; actions（动作）</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/16.png?raw=true" alt="16"><figcaption class="figure__caption">16</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;右上角“Create Actions”（创建动作）</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/17.png?raw=true" alt="17"><figcaption class="figure__caption">17</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Name（名称）自定义，我这里写”baojing”,其他默认</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/18.png?raw=true" alt="18"><figcaption class="figure__caption">18</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后点右侧的“Operations”（操作）下的“New”（新的）按钮</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/19.png?raw=true" alt="19"><figcaption class="figure__caption">19</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;“Operation Type”（操作类型）选择“Send message”（送出消息）</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/20.png?raw=true" alt="20"><figcaption class="figure__caption">20</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;“Send Message to”（送到用户组）选择一个或多个要发送消息的用户组</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/21.png?raw=true" alt="21"><figcaption class="figure__caption">21</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Send to Users选择我们之前新增的test1</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/22.png?raw=true" alt="22"><figcaption class="figure__caption">22</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;“Send only to”（仅送到）选择baojing </p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/23.png?raw=true" alt="23"><figcaption class="figure__caption">23</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;点一下add，最后点save</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E9%85%8D%E7%BD%AE%E9%82%AE%E4%BB%B6%E5%91%8A%E8%AD%A6/24.png?raw=true" alt="24"><figcaption class="figure__caption">24</figcaption></figure></p>

	

	
		<span class="different-posts"><a href="/2017/10/12/Zabbix/9. zabbix 配置邮件告警/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
